package com.dmy.vo.helper;

import com.dmy.vo.FriendListVo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;

/**
 * create by huahuadelei for 2020/1/12
 */
public class JAVA8GroupHandler implements FriendListGroupHandler {
    private final List<FriendListVo> listVos;

    public JAVA8GroupHandler() {
        this.listVos = new ArrayList<>();
    }

    @Override
    public void push(FriendListVo friendListVo) {
        listVos.add(friendListVo);
    }

    @Override
    public Map<String, List<FriendListVo>> groupResult() {
        Map<String, List<FriendListVo>> groupMap = listVos.stream().collect(Collectors.groupingBy(f -> f.getCharCase()));

        TreeMap<String, List<FriendListVo>> treeMap = new TreeMap<>((k1,k2)-> k1.compareToIgnoreCase(k2));
        treeMap.putAll(groupMap);
        return treeMap;
    }
}
